import 'dart:async';

import 'package:black_movice/routers.dart';
import 'package:black_movice/utils/Utils.dart';
import 'package:black_movice/utils/local_storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  Timer? timer;
  void _init() async {
    // 获取token
    var token = await LocalStorage.getToken();
    // 如果有token则三秒后跳入主页
    if (token != null) {
      Utils.logDebug("我获取token:$token");
      // timer = Timer(const Duration(seconds: 3), () => Get.toNamed(RoutersPageVC.register));
    }
    timer = Timer(const Duration(seconds: 1), () => Get.offNamed(Routers.home));
  }

  @override
  void initState() {
    super.initState();
    _init();
  }

  @override
  void dispose() {
    timer?.cancel();
    timer = null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return const Placeholder(
      child: Center(
        child: Text("启动页面"),
      ),
    );
  }
}
